<template>
    <p v-for="(item, key) in alerts" :key="key">
        <span v-html="item"></span>
    </p>
</template>
<script setup>
import { get,post } from '@/utils/request.js'
import {ElMessage} from 'element-plus'
import { ref,onMounted } from 'vue'
import {userStore} from '@/stores/counter.js'
import moment from 'moment'

const alerts=ref([])
const store=userStore()

onMounted(async () => {
   init();
})

const highlightChinese=(text)=> {
console.log(text)
text = text.replace(/不通过/g, "<span style='color: red;'>不通过</span>")
      text = text.replace(/通过/g, "<span style='color: red;'>通过</span>")
      return text;
    }

const init=()=>{
 get('/data/all',(message)=>{
 let bbb=[];
 let aaa=[];
 if(store.auth.role=='管理员')
     bbb=message;
     else bbb = message.filter(item=>item.name===store.auth.user);
     for(let i=0;i<bbb.length;i++){
     if(bbb[i].state==='审核通过'){
     aaa[i]=bbb[i].name+"在"+bbb[i].uploadTime+"上传的数据已经审核通过了";
     }else if(bbb[i].state==='审核不通过'){
      aaa[i]=bbb[i].name+"在"+moment(bbb[i].uploadTime).format('YYYY-MM-DD')+"上传的数据审核不通过,请重新上传";
     }
     }
     alerts.value=aaa.map(item => highlightChinese(item));
})
}
</script>
<style scoped>
</style>